﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BT_Mang_Nhom13.Library;
using BT_Mang_Nhom13.Checker;

namespace BT_Mang_Nhom13.Sorter
{
    public class InterchangeSorter<T>: MySorter<T> where T : IComparable<T>
    {
        //Sort theo delegate
        public override T[] Sort(T[] Data, Func<T, T, int> Compare)
        {
            for (int i = 0; i < Data.Length - 1; i++)
            {
                for (int j = i + 1; j < Data.Length;j++)
                {
                   if (Compare(Data[i], Data[j]) > 0)
                   {
                       Swap(Data, i, j);
                   }
                }
            }

            return Data;
        }

        public override T[] Sort(T[] Data, MyComparer<T> Comparer)
        {
            for (int i = 0; i < Data.Length - 1; i++)
            {
                for (int j = i + 1; j < Data.Length; j++)
                {
                    if (Comparer.CompareTo(Data[i], Data[j]) > 0)
                    {
                        Swap(Data, i, j);
                    }
                }
            }

            return Data;
        }
       
    }
}
